package com.cf.r1042_ak;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class c {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(System.out);
        in.nextToken();
        int T = (int) in.nval;
        while (T-- > 0) {
            in.nextToken(); int n = (int) in.nval;
            in.nextToken(); int k = (int) in.nval;
            int[] s = new int[n];
            int[] t = new int[n];
            for (int i = 0; i < n; i++) {
                in.nextToken(); s[i] = (int) in.nval;
            }
            for (int i = 0; i < n; i++) {
                in.nextToken(); t[i] = (int) in.nval;
            }
            if (k == 0) {
                Map<Integer, Integer> cnt = new HashMap<>();
                for (int x : s) {
                    cnt.put(x, cnt.getOrDefault(x, 0) + 1);
                }
                for (int x : t) {
                    if (!cnt.containsKey(x)) {
                        out.println("No");
                        cnt = null;
                        break;
                    }
                    int v = cnt.get(x);
                    if (v == 1) cnt.remove(x);
                    else cnt.put(x, v - 1);
                }
                if (cnt != null) out.println(cnt.isEmpty() ? "YES" : "NO");
                continue;
            }
            Map<Integer, Integer> cnts = new HashMap<>();
            Map<Integer, Integer> cntt = new HashMap<>();
            for (int x : s) {
                int r = x % k;
                int i = Math.min(r, k - r);
                cnts.put(i, cnts.getOrDefault(i, 0) + 1);
            }
            for (int x : t) {
                int r = x % k;
                int i = Math.min(r, k - r);
                cntt.put(i, cntt.getOrDefault(i, 0) + 1);
            }
            out.println(cnts.equals(cntt) ? "YES" : "NO");
        }
        out.flush();
        out.close();
        br.close();
    }

}